const express = require('express');
const req = require("express/lib/request");
const path = require("node:path");
const app = express();

const config={};

function fun1(req,res,next){
    config.hour=new Date().getHours();
    config.minute=new Date().getMinutes();
    next();
}

function fun2(req,res,next){
    config.day=new Date().getDate();
    config.month=new Date().getMonth()+1;
    //console.log(`${new Date().getDate()}`);
    //console.log(req.number + ':' + res.number);
   // res.send('<h1 style="color:green">' + req.number + ':' + res.number + '</h1>');
    next();
}

app.use(express.static(path.join('D:','Images')));
console.log(path.join('D:','Images'));

app.use(fun1);
app.use('/time',fun2);

app.get('/time/:id', (req, res) => {
    const id=req.params.id;
    res.writeHead(200,{'Content-Type':'text/html'});
    const image=`img${id}.jpg`
    console.log(image);
    console.log(req.params.id);
    res.end('<img src="' + `img${id}.jpg` +'" width="50%"/>');
    //res.send('<h1 style="color:green">' + id + ':'+ config.month +':'+ config.day + ':'+ config.hour+ '</h1>');
    // res.send('<h2 style="color:green">' + config.month + '</h2>');
    // res.send('<h2 style="color:green">' + config.day + '</h2>');
    // res.send('<h2 style="color:green">' + config.hour + '</h2>');
    // res.send('<h2 style="color:green">' + config.minute + '</h2>');
});

app.listen(8080, () => {
    console.log("Server started on port 8080");
});
